﻿using B.S.DataBase.MyProject.Domain.productionworkorder;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.SCWorkOrderCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.SCWorkOrderCommandHandler
{
    /// <summary>
    /// 生产工单里的质检操作命令处理方法
    /// </summary>
    public class SCWorkOrderZJCommandHandler:IRequestHandler<SCWorkOrderZJCommand,APIResult<int>>
    {
        /// <summary>
        /// 工序流程仓储接口
        /// </summary>
        private readonly IBaseRepository<ProcessFlowSheet> pRepo;
        /// <summary>
        ///构造方法 
        /// </summary>
        /// <param name="pRepo"></param>
        public SCWorkOrderZJCommandHandler(IBaseRepository<ProcessFlowSheet>pRepo)
        {
            this.pRepo = pRepo;
        }
        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<int>> Handle(SCWorkOrderZJCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<int> result = new APIResult<int>();
                var list = pRepo.GetAll().Result.Where(x => x.ProcessFlowSheetId == request.ProcessFlowSheetId).FirstOrDefault();
                list.HeGeNumber = request.HeGeNumber;
                list.BuLiANGnumber = request.BuLiANGnumber;
                list.ZJStatus = true;
                int r = pRepo.Update(list).Result;
                if (r > 0)
                {
                    result.Code = APIEnum.修改成功;
                    result.Msg = APIEnum.修改成功.ToString();
                    result.data = r;
                }
                else
                {
                    result.Code = APIEnum.修改失败;
                    result.Msg = APIEnum.修改失败.ToString();
                    result.data = r;
                }
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }

        }



    }


}
